package rabbitmq

import (
	"encoding/json"
	"github.com/streadway/amqp"
)

type RbChannel struct {
	rabbitMq   *rabbitMqLater
	Delivery   *amqp.Delivery
	Command    string
	Parameters map[string]interface{}
}

func (r *RbChannel) getParams() bool {
	message := r.Delivery.Body
	switch r.rabbitMq.contentType {
	case "json":
		json.Unmarshal(message, &r.Parameters)
		return true
	default:
		return false
	}
}

func (r *RbChannel) Analysis() bool {
	if r.getParams() {
		if r.Command != "" {
			return true
		} else {
			return false
		}
	} else {
		return false
	}
}

func (r *RbChannel) Push(body string) {
	r.rabbitMq.Push(body)
}

func (r *RbChannel) PushSelf(body string) {
	r.rabbitMq.PushSelf(body)
}
